package com.example.shiro.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ Author     ：jujh
 * @ Date       ：Created in 14:17 2018/11/1
 * @ Description：
 */
@RestController
public class MailController {

    @Autowired
    private JavaMailSender mailSender; //框架自带的

    @Autowired
    JavaMailSender jms;

    @GetMapping("/send")
    public String send() {
        //建立邮件消息
        SimpleMailMessage mainMessage = new SimpleMailMessage();
        //发送者
        mainMessage.setFrom("1163291535@qq.com");
        //接收者
        mainMessage.setTo("2224757326@qq.com");
        //发送的标题
        mainMessage.setSubject("嗨喽");
        //发送的内容
        mainMessage.setText("hello world");
        jms.send(mainMessage);
        return "1";
    }

    @GetMapping("/sendemail")
    public String sendemail() {
        String from = "GONGXUEJJH@163.com";
        String title = "测试邮件";
        String email = "1163291535@qq.com";
        String url = "测试邮件-url";
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from); // 发送人的邮箱
        message.setSubject(title); //标题
        message.setTo(email); //发给谁  对方邮箱
        message.setText(url); //内容
        mailSender.send(message); //发送
        return "success";
    }

}
